package jin.si.com.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description: 配置拦截路径
 * @ClassName TestInterceptorUrl
 * @Author MT
 * @Date 2021/5/12 11:27
 **/
@Configuration //替换以前的springMvc.xml
public class TestInterceptorUrl implements WebMvcConfigurer {

    //配置拦截路径 （添加拦截路径 拦截路径可以添加多个）
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(getInterceptro()).addPathPatterns("/getInter/**");
        registry.addInterceptor(getInterceptro()).addPathPatterns("/getInter/addOrder2","/getInter/addOrder3");

        registry.addInterceptor(getTestResponseInterceptor()).addPathPatterns("/**");

        WebMvcConfigurer.super.addInterceptors(registry);
    }

    //配置拦截器bean，相当于springMvc.xml配置的bean
    @Bean
    public TestInterceptor getInterceptro() {

        return new TestInterceptor();
    }
    public TestResponseInterceptor getTestResponseInterceptor() {
        return new TestResponseInterceptor();
    }

}
